package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.PageResult;
import cn.wolfcode.mapper.EmpMapper;
import cn.wolfcode.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageResult query(int page, int pageSize, String name, Integer gender, Date begin, Date end) {

//        int start = (page - 1) * pageSize;
//        //查询两个参数
//        List<Emp> rows = empMapper.selForList(start, pageSize);
//        int totalCount = empMapper.selForCount();
        //给插件设置分页参数
        PageHelper.startPage(page, pageSize);
        //正常执行查询
        List<Emp> emps = empMapper.List(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) emps;
        return new PageResult(p.getTotal(), p.getResult());
    }
}
